$(function (){
    $('.btn-get').click(function (){
        let qq = $('#qq').val().toString().trim();
        let countdown = 60;
        if (virifyQq(qq)){
            // 倒秒计时
            countDown(countdown);

            $('.btn-get').css('display', 'none');
            $('.count-down').css('display', 'block');

            // ajax 请求验证码
            sendQqVerify(qq);
        }else {
            alert("qq号格式错误！");
        }
    })
})

// 发送验证码
function sendQqVerify(qq){
    $.ajax({
        async: false,
        type: "post",
        url: "/sendQqVerify",
        dataType: "json",
        data: {qq: qq},
        success: function (data){
            console.log("请求成功！");
            console.log("qq：" + qq);
        },
        error: function (data){
            console.log("请求失败！");
        }
    })
}

function virifyQq(qq){
    // 正则表达式
    return true;
}

// 倒秒计时
function countDown(countdown){
    let text = '后重发';
    // 定时倒秒
    timer = setInterval(function (){
        countdown--;
        if (countdown == 0){
            $('.btn-get').css('display', 'block');
            $('.count-down').css('display', 'none');
            clearInterval(timer);
        }
        $('.count-down').html("重新发送(" + countdown + ")");
    },1000);
}